import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

/**
 * @Description: 自定义实现定时器
 * @Auther: dongwq
 * @Date: 2021/5/27 11:01
 * @company：CTTIC
 */
public class MyQuartz {

    private static final Logger logger = LoggerFactory.getLogger(MyQuartz.class);

    public static void main(String[] args) throws SchedulerException, InterruptedException {

        logger.info("my quartz is starting!");

        //创建定时调度器
        StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = stdSchedulerFactory.getScheduler();

        //创建jobdetail详情
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity("job1", "group1").build();

        //创建触发器
        SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trgger1", "triggerGroup1")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).repeatForever())
                .build();
        //执行
        scheduler.scheduleJob(jobDetail, trigger);
        logger.info("scheduler start !-------------");
        scheduler.start();

        //睡眠
//        TimeUnit.MINUTES.sleep(1);
//        scheduler.shutdown();
        logger.info("scheduler shutdown !-------------");


    }
}
